package com.siwei.mes.service.laboratory.factory.material;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.entity.experiment.CheckBatchConfig;
import com.siwei.mes.entity.experiment.Experiment;
import com.siwei.mes.entity.experiment.ExperimentDetail;
import com.siwei.mes.entity.experiment.cement.*;
import com.siwei.mes.entity.experiment.coarseAggregate.*;
import com.siwei.mes.entity.experiment.concreteAdmixture.*;
import com.siwei.mes.entity.experiment.fineAggregate.*;
import com.siwei.mes.entity.experiment.flyAsk.*;
import com.siwei.mes.entity.experiment.slag.*;
import com.siwei.mes.entity.system.TestProjectInfo;
import com.siwei.mes.entity.system.TestProjectSpecConfig;
import com.siwei.mes.enums.MaterialsEnum;
import com.siwei.mes.enums.TestProjectEnum;
import com.siwei.mes.mapper.experiment.CheckBatchConfigMapper;
import com.siwei.mes.mapper.experiment.ExperimentMapper;
import com.siwei.mes.mapper.system.TestProjectInfoMapper;
import com.siwei.mes.mapper.system.TestProjectSpecConfigMapper;
import com.siwei.mes.service.laboratory.factory.entity.LaboratoryDownloadVo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 原材料上传到协会 工厂主方法
 *
 * @Description: 原材料上传到协会 工厂主方法
 * @Version: 1.0
 * @author: mlchen
 * @date: 2025/3/29 16:27
 */
@Service
public class MaterialLaboratoryFactoryService {
    private static final Logger log = LoggerFactory.getLogger("laboratory");

    @Resource
    private CheckBatchConfigMapper checkBatchConfigMapper;
    @Resource
    private TestProjectInfoMapper testProjectInfoMapper;
    @Resource
    private TestProjectSpecConfigMapper testProjectSpecConfigMapper;
    @Resource
    private ExperimentMapper experimentMapper;

    /**
     * 上传到协会
     *
     * @param sampleNo             样品编码
     * @param experimentDetailList 试验委托详情信息
     * @param experiment           试验委托信息
     * @param samId                产品编号
     */
    public void processUpload(String sampleNo, List<ExperimentDetail> experimentDetailList, Experiment experiment, String samId) {
        Integer experimentType = experiment.getExperimentType();
        MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(experimentType);
        if (materialsEnum == null) {
            log.error("原材料上传到协会，未找到对应实验类型：【{}】直接跳过", experimentType);
            return;
        }

        log.info("开始处理原材料上传到协会，对应实验类型：【{}】,名称：【{}】", experimentType, materialsEnum.getName() + "-" + materialsEnum.getName());

        /**批检指标配置*/
        List<CheckBatchConfig> batchConfigList = checkBatchConfigMapper.getList(new CheckBatchConfig().setIsDel(0).setProjectCategory(materialsEnum.getCode()));
        /**查询出品控试验项目配置*/
        List<TestProjectInfo> testProjectInfoList = testProjectInfoMapper.getList(new TestProjectInfo().setTestType(materialsEnum.getTestProjectType()));
        /**查询 试验项目材料规格判定配置*/
        List<TestProjectSpecConfig> testProjectSpecConfigList = testProjectSpecConfigMapper.getList(new TestProjectSpecConfig().setTestProjectType(materialsEnum.getTestProjectType()));


        for (ExperimentDetail detail : experimentDetailList) {
            String testProjectCode = detail.getTestProjectCode();
            String testProjectName = detail.getTestProjectName();
            if (StringUtils.isBlank(testProjectCode)) {
                log.error("未找到对应试验项目code：【{}】，试验项目名称：【{}】", testProjectCode, materialsEnum.getName() + "-" + testProjectName);
                return;
            }
            //判断试验项目中平均值是否为空
            if (!isOrNull(detail, experiment)) {
                log.info("平均值为空，暂不上传试验结果！对应试验项目code：【{}】，试验项目名称：【{}】,委托编号：【{}】", testProjectCode, materialsEnum.getName() + "-" + testProjectName,experiment.getExperimentNo());
                continue;
            }
            log.info("查找原材料工厂选择器，对应试验项目code：【{}】，试验项目名称：【{}】", testProjectCode, materialsEnum.getName() + "-" + testProjectName);

            JSONObject objJson = detail.getObjJson();

            MaterialLaboratoryFactory factory = MaterialLaboratoryFactorySelector.getFactory(testProjectCode);
            if (factory != null) {
                factory.processUpload(objJson, sampleNo, experiment, batchConfigList, testProjectInfoList, testProjectSpecConfigList, detail, samId);
            }
            //else {
            //    // 处理未匹配到工厂的情况
            //    log.error("未找到匹配的混凝土工厂：【{}】，试验项目名称：【{}】，不需要上传!", testProjectCode, materialsEnum.getName() + "-" + testProjectName);
            //}
        }
    }

    /**
     * 处理下载
     *
     * @param sampleNo             样品编码
     * @param experimentDetailList 试验委托详情信息
     * @param experiment           试验委托信息
     * @param wtSampleList         协会数据
     * @param samId                产品编号
     */
    public void processDownload(String sampleNo, List<ExperimentDetail> experimentDetailList, Experiment experiment, Map<String, Object> wtSampleList, String samId) {
        Integer experimentType = experiment.getExperimentType();
        MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(experimentType);
        if (materialsEnum == null) {
            log.error("协会原材料下载到品控，未找到对应实验类型：【{}】直接跳过", experimentType);
            return;
        }

        log.info("开始处理协会原材料下载到品控，对应实验类型：【{}】,名称：【{}】", experimentType, materialsEnum.getName());

        List<TestProjectInfo> testProjectInfoList = testProjectInfoMapper.getList(new TestProjectInfo().setTestType(materialsEnum.getTestProjectType()));
        //获取到所有试验项目
        String[] examParameterCn = wtSampleList.get("Exam_parameter_Cn").toString().split(";");
        String[] status = wtSampleList.get("Status").toString().split(";");
        Map<String, String> parameterMap = new HashMap<>();
        for (int i = 0; i < examParameterCn.length; i++) {
            if (StringUtils.isNotBlank(examParameterCn[i]) && StringUtils.isNotBlank(status[i])) {
                //根据试验项目查询到对照的品控试验项目名称
                for (TestProjectInfo testProjectInfo : testProjectInfoList) {
                    if (StringUtils.isNotBlank(testProjectInfo.getParameterName())) {
                        if (testProjectInfo.getParameterName().contains(examParameterCn[i])) {
                            parameterMap.put(testProjectInfo.getTestCode(), status[i]);
                        }
                    }
                }
            }
        }

        //试验依据
        Set<String> experimentGistList = new HashSet<>();
        //判断依据
        Set<String> judgeGistList = new HashSet<>();
        //仪器
        Set<String> equipmentList = new HashSet<>();
        //温度
        String temperature = "";
        //湿度
        String humidness = "";


        for (ExperimentDetail detail : experimentDetailList) {
            String testProjectCode = detail.getTestProjectCode();
            if (StringUtils.isBlank(testProjectCode)) {
                log.error("未找到对应试验项目code：【{}】", testProjectCode);
                return;
            }
            log.info("查找原材料工厂选择器，对应试验项目code：【{}】", testProjectCode);

            MaterialLaboratoryFactory factory = MaterialLaboratoryFactorySelector.getFactory(testProjectCode);
            if (factory != null) {
                LaboratoryDownloadVo downloadVo = factory.processDownload(sampleNo, experiment, detail, parameterMap, samId, testProjectInfoList);
                if (downloadVo == null) {
                    continue;
                }
                if (StringUtils.isNotBlank(downloadVo.getExperimentGist())) {
                    experimentGistList.add(downloadVo.getExperimentGist());
                }
                if (StringUtils.isNotBlank(downloadVo.getJudgeGist())) {
                    judgeGistList.add(downloadVo.getJudgeGist());
                }
                if (StringUtils.isNotBlank(downloadVo.getEquipment())) {
                    equipmentList.add(downloadVo.getEquipment());
                }
                if (StringUtils.isNotBlank(downloadVo.getTemperature())) {
                    temperature = downloadVo.getTemperature();
                }
                if (StringUtils.isNotBlank(downloadVo.getHumidness())) {
                    humidness = downloadVo.getHumidness();
                }

                if (!downloadVo.getEquipmentList().isEmpty()) {
                    equipmentList.addAll(downloadVo.getEquipmentList());
                }
                if (!downloadVo.getJudgeGistList().isEmpty()) {
                    judgeGistList.addAll(downloadVo.getJudgeGistList());
                }
                if (!downloadVo.getExperimentGistList().isEmpty()) {
                    experimentGistList.addAll(downloadVo.getExperimentGistList());
                }
            } else {
                // 处理未匹配到工厂的情况
                log.error("未找到匹配的原材料工厂：【{}】，不需要上传!", testProjectCode);
            }
        }

        String experimentGists = "";
        String judgeGists = "";
        String equipmentGists = "";

        for (String experimentGist : experimentGistList) {
            if (StringUtils.isBlank(experimentGists)) {
                experimentGists = experimentGist;
            } else {
                experimentGists = experimentGists + ";" + experimentGist;
            }
        }
        for (String judgeGist : judgeGistList) {
            if (StringUtils.isBlank(judgeGists)) {
                judgeGists = judgeGist;
            } else {
                judgeGists = judgeGists + ";" + judgeGist;
            }
        }
        for (String equipment : equipmentList) {
            if (StringUtils.isBlank(equipmentGists)) {
                equipmentGists = equipment;
            } else {
                equipmentGists = equipmentGists + ";" + equipment.replaceAll(";", "");
            }
        }

        //修改台账主表数据
        experiment.setExperimentGist(experimentGists);
        experiment.setJudgeGist(judgeGists);
        experiment.setEquipment(equipmentGists);
        experiment.setTemperature(temperature);
        experiment.setHumidness(humidness);
        experimentMapper.updateByPrimaryKeySelective(experiment);
    }


    private boolean isOrNull(ExperimentDetail detail, Experiment experiment) {

        //原材料类型为 ：水泥
        if (MaterialsEnum.CEMENT.getCode().equals(experiment.getExperimentType())) {
            return cement(detail);
        } else if (MaterialsEnum.FLY.getCode().equals(experiment.getExperimentType())) {
            return fly(detail);
        } else if (MaterialsEnum.SLAG.getCode().equals(experiment.getExperimentType())) {
            return slag(detail);
        } else if (MaterialsEnum.COARSE.getCode().equals(experiment.getExperimentType())) {
            return coarse(detail);
        } else if (MaterialsEnum.FINE.getCode().equals(experiment.getExperimentType())) {
            return fine(detail);
        } else if (MaterialsEnum.ADMIXTURE.getCode().equals(experiment.getExperimentType())) {
            return admixture(detail);
        }

        return false;
    }


    //外加剂
    private boolean admixture(ExperimentDetail detail) {
        JSONObject objJson = detail.getObjJson();

        //PH值
        if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_PHZ.getCode())) {
            //将json转成对象
            ConcreteAdmixturePhz concreteAdmixturePhz = objJson.toJavaObject(ConcreteAdmixturePhz.class);
            if (concreteAdmixturePhz != null && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixturePhz.getPjph())) {
                return true;
            }
            //密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_MD.getCode())) {
            //将json转成对象
            ConcreteAdmixtureMd concreteAdmixtureMd = objJson.toJavaObject(ConcreteAdmixtureMd.class);
            if (concreteAdmixtureMd != null && concreteAdmixtureMd.getJmmdInfo() != null && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureMd.getJmmdInfo().getMdpjz())) {
                return true;
            }
            //含固量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_HGL.getCode())) {
            //将json转成对象
            ConcreteAdmixtureHgl concreteAdmixtureHgl = objJson.toJavaObject(ConcreteAdmixtureHgl.class);
            if (concreteAdmixtureHgl != null && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureHgl.getPjhgl())) {
                return true;
            }
            //凝结时间之差
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_NJSJZC.getCode())) {
            //将json转成对象
            ConcreteAdmixtureNjsjzc concreteAdmixtureNjsjzc = objJson.toJavaObject(ConcreteAdmixtureNjsjzc.class);
            if (concreteAdmixtureNjsjzc != null && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureNjsjzc.getCnsjzc()) && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureNjsjzc.getZnsjzc())) {
                return true;
            }
            //泌水率比
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_QSLB.getCode())) {
            //将json转成对象
            ConcreteAdmixtureQslb concreteAdmixtureQslb = objJson.toJavaObject(ConcreteAdmixtureQslb.class);
            if (concreteAdmixtureQslb != null && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureQslb.getQslb())) {
                return true;
            }
            //减水率
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_JSL.getCode())) {
            //将json转成对象
            ConcreteAdmixtureJSL concreteAdmixtureJSL = objJson.toJavaObject(ConcreteAdmixtureJSL.class);
            if (concreteAdmixtureJSL != null && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureJSL.getPjz())) {
                return true;
            }
            //塌落度1h经时变化量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CONCRETE_ADMIXTURE_PARAM_WJJ_TLD1HJSBHL.getCode())) {
            //将json转成对象
            ConcreteAdmixtureTld1hjsbhl concreteAdmixtureTld1hjsbhl = objJson.toJavaObject(ConcreteAdmixtureTld1hjsbhl.class);
            if (concreteAdmixtureTld1hjsbhl != null && concreteAdmixtureTld1hjsbhl.getSjhntObject() != null
                    && org.apache.commons.lang.StringUtils.isNotBlank(concreteAdmixtureTld1hjsbhl.getSjhntObject().getH1bhlpjz())) {
                return true;
            }
        }


        return false;
    }

    //细骨料
    private boolean fine(ExperimentDetail detail) {
        JSONObject objJson = detail.getObjJson();
        //含泥量
        if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_HNL.getCode())) {
            //将json转成对象
            FineAggregateHnl fineNnl = objJson.toJavaObject(FineAggregateHnl.class);
            if (fineNnl != null && org.apache.commons.lang.StringUtils.isNotBlank(fineNnl.getHnlpjz())) {
                return true;
            }


            //含水率
        }else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_HSL.getCode())) {
            FineAggregateHsl fineHsl = objJson.toJavaObject(FineAggregateHsl.class);
            if (fineHsl != null && StringUtils.isNotBlank(fineHsl.getPjz())) {
                return true;
            }

            //压碎指标值
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_YSZZB.getCode())) {
            //将json转成对象
            FineAggregateYszzb fineYszzb = objJson.toJavaObject(FineAggregateYszzb.class);
            if (fineYszzb != null && org.apache.commons.lang.StringUtils.isNotBlank(fineYszzb.getZyszb())) {
                return true;
            }
            //表观密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_BGMD.getCode())) {
            //将json转成对象
            FineAggregateBgmd fineBgmd = objJson.toJavaObject(FineAggregateBgmd.class);
            if (fineBgmd != null && org.apache.commons.lang.StringUtils.isNotBlank(fineBgmd.getPjz())) {
                return true;
            }
            //堆积密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_DJMD.getCode())) {
            //将json转成对象
            FineAggregateDjmd fineDjmd = objJson.toJavaObject(FineAggregateDjmd.class);
            if (fineDjmd != null && org.apache.commons.lang.StringUtils.isNotBlank(fineDjmd.getPjz())) {
                return true;
            }
            //紧密密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_JMMD.getCode())) {
            //将json转成对象
            FineAggregateJmmd fineJmmd = objJson.toJavaObject(FineAggregateJmmd.class);
            if (fineJmmd != null && org.apache.commons.lang.StringUtils.isNotBlank(fineJmmd.getPjz())) {
                return true;
            }
            //筛分析
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_SFX.getCode())) {
            return true;
            //将json转成对象
          /*  FineAggregateSfx fineSfx = objJson.toJavaObject(FineAggregateSfx.class);
            if (fineSfx != null && StringUtils.isNotBlank(fineSfx.getXdmspjz())) {

            }*/
            //泥块含量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_NKHL.getCode())) {
            //将json转成对象
            FineAggregateNkhl fineNkhl = objJson.toJavaObject(FineAggregateNkhl.class);
            if (fineNkhl != null && org.apache.commons.lang.StringUtils.isNotBlank(fineNkhl.getPjz())) {
                return true;
            }
            //氯离子含量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_LLZHL.getCode())) {
            //将json转成对象
            FineAggregateLlzhl llzhl = objJson.toJavaObject(FineAggregateLlzhl.class);
            if (llzhl != null && org.apache.commons.lang.StringUtils.isNotBlank(llzhl.getPjz())) {
                return true;
            }
            //胶砂流动度
        }else if (detail.getTestProjectCode().equals(TestProjectEnum.FINE_AGGREGATE_PARAM_XGL_JSLDD.getCode())) {
            FineAggregateJsldd fineJsldd = objJson.toJavaObject(FineAggregateJsldd.class);
            if(fineJsldd != null &&  StringUtils.isNotBlank(fineJsldd.getDxjl())){
                return true;
            }
        }


        return false;
    }

    //粗骨料
    private boolean coarse(ExperimentDetail detail) {
        JSONObject objJson = detail.getObjJson();
        //含泥量
        if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_HNL.getCode())) {
            //将json转成对象
            CoarseAggregateHnl coarseHnl = objJson.toJavaObject(CoarseAggregateHnl.class);
            if (coarseHnl != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseHnl.getHnlpjz())) {
                return true;
            }
            //含泥块量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_HNKL.getCode())) {
            //将json转成对象
            CoarseAggregateHnkl coarseHnkl = objJson.toJavaObject(CoarseAggregateHnkl.class);
            if (coarseHnkl != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseHnkl.getHnlpjz())) {
                return true;
            }
            //针、片状颗粒含量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_ZPZKLHL.getCode())) {
            //将json转成对象
            CoarseAggregateZpzklhl coarseZpzklhl = objJson.toJavaObject(CoarseAggregateZpzklhl.class);
            if (coarseZpzklhl != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseZpzklhl.getZpzkklhl())) {
                return true;
            }
            //筛分析
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_SFX.getCode())) {
            return true;
            //将json转成对象
        /*    CoarseAggregateSfx coarseSfx = objJson.toJavaObject(CoarseAggregateSfx.class);
            if (coarseSfx != null && StringUtils.isNotBlank(coarseSfx.getDxjl())) {
                return true;
            }*/
            //压碎值指标
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_YSZZB.getCode())) {
            //将json转成对象
            CoarseAggregateYszzb coarseYszzb = objJson.toJavaObject(CoarseAggregateYszzb.class);
            if (coarseYszzb != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseYszzb.getPjz())) {
                return true;
            }
            //表观密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_BGMD.getCode())) {
            //将json转成对象
            CoarseAggregateBgmd coarseBgmd = objJson.toJavaObject(CoarseAggregateBgmd.class);
            if (coarseBgmd != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseBgmd.getPjz())) {
                return true;
            }
            //堆积密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_DJMD.getCode())) {
            //将json转成对象
            CoarseAggregateDjmd coarseDjmd = objJson.toJavaObject(CoarseAggregateDjmd.class);
            if (coarseDjmd != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseDjmd.getPjz())) {
                return true;
            }
            //紧密密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.COARSE_AGGREGATE_PARAM_CGL_JMMD.getCode())) {
            //将json转成对象
            CoarseAggregateJmmd coarseJmmd = objJson.toJavaObject(CoarseAggregateJmmd.class);
            if (coarseJmmd != null && org.apache.commons.lang.StringUtils.isNotBlank(coarseJmmd.getPjz())) {
                return true;
            }
        }

        return false;
    }

    //水泥
    private boolean cement(ExperimentDetail detail) {
        JSONObject objJson = detail.getObjJson();
        //安定性
        if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_ADX.getCode())) {
            return true;
            //将json转成对象
            /*CementAdx cementAdx = objJson.toJavaObject(CementAdx.class);
            if (cementAdx != null && cementAdx.getSbf() != null && StringUtils.isNotBlank(cementAdx.getSbf().getJl())) {
                return true;
            }*/
            //水泥标准稠度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_BZCD.getCode())) {
            //将json转成对象
            CementBzcd cementBzcd = objJson.toJavaObject(CementBzcd.class);
            if (cementBzcd != null && org.apache.commons.lang.StringUtils.isNotBlank(cementBzcd.getBzcdysl())) {
                return true;
            }
            //水泥凝结时间
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_NJSJ.getCode())) {
            //将json转成对象
            CementNjsj cementNjsj = JsonUtils.getObject(objJson, CementNjsj.class);
            if (cementNjsj != null && cementNjsj.getJgjs() != null && org.apache.commons.lang.StringUtils.isNotBlank(cementNjsj.getJgjs().getCnsj()) && org.apache.commons.lang.StringUtils.isNotBlank(cementNjsj.getJgjs().getZnsj())) {
                return true;
            }
            //水泥强度测定
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_QDCD.getCode())) {
            return true;
            //水泥的强度测定要强制默认必须上传（因为强度测定是要在协会里面输入，自动同步过来，本地不会填）
          /*  //将json转成对象
            CementQdcd cementQdcd = JsonUtils.getObject(objJson, CementQdcd.class);
            //水泥的强度测定要强制默认必须上传（因为强度测定是要在协会里面输入，自动同步过来，本地不会填）
            return true;
           /* if (cementQdcd != null && cementQdcd.getKzqdsy28d() != null && StringUtils.isNotBlank(cementQdcd.getKzqdsy28d().getPjz())) {
                return true;
            }*/
            //水泥细度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_XD.getCode())) {
            //将json转成对象
            CementXd cementXd = JsonUtils.getObject(objJson, CementXd.class);
            if (cementXd != null && org.apache.commons.lang.StringUtils.isNotBlank(cementXd.getPjz())) {
                return true;
            }
            //水泥密度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_MD.getCode())) {
            //将json转成对象
            CementMd cementMd = JsonUtils.getObject(objJson, CementMd.class);
            if (cementMd != null && org.apache.commons.lang.StringUtils.isNotBlank(cementMd.getPjz())) {
                return true;
            }
            //比表面积
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.CEMENT_PARAM_BBMJ.getCode())) {
            //将json转成对象
            CementBbmj cementBbmj = objJson.toJavaObject(CementBbmj.class);
            if (cementBbmj != null && org.apache.commons.lang.StringUtils.isNotBlank(cementBbmj.getPjz())) {
                return true;
            }
        }

        return false;
    }

    //矿渣粉
    private boolean slag(ExperimentDetail detail) {
        //品控试验json
        JSONObject objJson = detail.getObjJson();
        //密度
        if (detail.getTestProjectCode().equals(TestProjectEnum.SLAG_PARAM_KZF_YPMD.getCode())) {
            //将json转成对象
            SlagYpmd slagYpmd = objJson.toJavaObject(SlagYpmd.class);
            if (slagYpmd != null && org.apache.commons.lang.StringUtils.isNotBlank(slagYpmd.getPjz())) {
                return true;
            }
            //烧失量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.SLAG_PARAM_KZF_SSL.getCode())) {
            //将json转成对象
            SlagSsl slagSsl = objJson.toJavaObject(SlagSsl.class);
            if (slagSsl != null && org.apache.commons.lang.StringUtils.isNotBlank(slagSsl.getSslpjz())) {
                return true;
            }
            //流动度比
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.SLAG_PARAM_KZF_LDDB.getCode())) {
            //将json转成对象
            SlagLddb slagLddb = objJson.toJavaObject(SlagLddb.class);
            if (slagLddb != null && org.apache.commons.lang.StringUtils.isNotBlank(slagLddb.getSyjg())) {
                return true;
            }
            //含水率
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.SLAG_PARAM_KZF_HSL.getCode())) {
            //将json转成对象
            SlagHsl slagHsl = objJson.toJavaObject(SlagHsl.class);
            if (slagHsl != null && org.apache.commons.lang.StringUtils.isNotBlank(slagHsl.getHsl())) {
                return true;
            }
            //活性指数
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.SLAG_PARAM_KZF_HXZS.getCode())) {
            return true;
            //将json转成对象
           /* SlagHdzs slagHdzs = objJson.toJavaObject(SlagHdzs.class);
            if (slagHdzs != null && slagHdzs.getHxzsInfoList().size() > 1 && StringUtils.isNotBlank(slagHdzs.getHxzsInfoList().get(1).getHxzs())) {
                return true;
            }*/
            //比表面积
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.SLAG_PARAM_KZF_BBMJ.getCode())) {
            //将json转成对象
            SlagBbmj slagBbmj = objJson.toJavaObject(SlagBbmj.class);
            if (slagBbmj != null && org.apache.commons.lang.StringUtils.isNotBlank(slagBbmj.getPjz())) {
                return true;
            }
        }


        return false;
    }

    //粉煤灰
    private boolean fly(ExperimentDetail detail) {
        //品控试验json
        JSONObject objJson = detail.getObjJson();
        //安定性
        if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_ADX.getCode())) {
            //将json转成对象
            FlyAskAdx flyAskAdx = objJson.toJavaObject(FlyAskAdx.class);
            if (flyAskAdx != null && flyAskAdx.getLsf() != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskAdx.getLsf().getPjz())) {
                return true;
            }
            //含水量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_HSL.getCode())) {
            //将json转成对象
            FlyAskHsl flyAskHsl = objJson.toJavaObject(FlyAskHsl.class);
            if (flyAskHsl != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskHsl.getHsl())) {
                return true;
            }
            //细度
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_XD.getCode())) {
            //将json转成对象
            FlyAskXd flyAskXd = objJson.toJavaObject(FlyAskXd.class);
            if (flyAskXd != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskXd.getJzhxddbz())) {
                return true;
            }
            //需水量比
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_XSLB.getCode())) {
            //将json转成对象
            FlyAskXslb flyAskXslb = objJson.toJavaObject(FlyAskXslb.class);
            if (flyAskXslb != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskXslb.getXslb())) {
                return true;
            }
            //三氧化硫
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_SYHL.getCode())) {
            //将json转成对象
            FlyAskSyhl flyAskSyhl = objJson.toJavaObject(FlyAskSyhl.class);
            if (flyAskSyhl != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskSyhl.getPjz())) {
                return true;
            }
            //游离氧化钙
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_YLYHG.getCode())) {
            //将json转成对象
            FlyAskYlyhg flyAskYlyhg = objJson.toJavaObject(FlyAskYlyhg.class);
            if (flyAskYlyhg != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskYlyhg.getPjz())) {
                return true;
            }
            //烧失量
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_SSL.getCode())) {
            //将json转成对象
            FlyAskSsl flyAskSsl = objJson.toJavaObject(FlyAskSsl.class);
            if (flyAskSsl != null && org.apache.commons.lang.StringUtils.isNotBlank(flyAskSsl.getSslpjz())) {
                return true;
            }
            //活性指数
        } else if (detail.getTestProjectCode().equals(TestProjectEnum.FLY_ASK_PARAM_FMH_HXZS.getCode())) {
            //将json转成对象
            FlyAskHdzs flyAskHdzs = objJson.toJavaObject(FlyAskHdzs.class);
            if (flyAskHdzs != null && flyAskHdzs.getHxzsInfoList() != null && flyAskHdzs.getHxzsInfoList().size() != 0 && org.apache.commons.lang.StringUtils.isNotBlank(flyAskHdzs.getHxzsInfoList().get(0).getHxzs())) {
                return true;
            }
        }


        return false;
    }
}
